package cn.gailvlun.gll.chatkit.dialog;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

import com.github.markzhai.recyclerview.BaseViewAdapter;

import cn.gailvlun.gll.chatlib.bean.SystemNotification;
import cn.gailvlun.gll.chatlib.dialog.Dialog;




public class DialogList extends RecyclerView {
    public DialogList(Context context) {
        this(context, null);
    }

    public DialogList(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DialogList(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    private DialogListAdapter mAdapter;

    @Override
    public void setAdapter(Adapter adapter) {
        throw new IllegalArgumentException("不能再使用该方法");
    }

    public void setDialogAdapter(DialogListAdapter adapter) {
        mAdapter = adapter;
        mAdapter.setPresenter(new Presenter());

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        setLayoutManager(linearLayoutManager);

        super.setAdapter(mAdapter);
    }

    public interface OnDialogClickListener {
        void onSystemNotificationClick();
        void onFriendNotificationClick();
        void onDialogClick(Dialog dialog);
    }
    private OnDialogClickListener mOnDialogClickListener;
    public void setOnDialogClickListener(OnDialogClickListener onDialogClickListener) {
        mOnDialogClickListener = onDialogClickListener;
    }

    public class Presenter implements BaseViewAdapter.Presenter {
        public void onClickSystemNotification() {
            if (mOnDialogClickListener != null) {
                mOnDialogClickListener.onSystemNotificationClick();
            }
        }

        public void onClickFriendNotification() {
            if (mOnDialogClickListener != null) {
                mOnDialogClickListener.onFriendNotificationClick();
            }
        }

        public void onClickDialog(Dialog item) {
            if (mOnDialogClickListener != null) {
                mOnDialogClickListener.onDialogClick(item);
            }
        }
    }
}
